<template>
    <div class="storeInfo">
        <div class="head">
            <div class="headForm" style="display:flex;justify-content:space-between;padding-right:10px">
                <p style="line-height:40px;padding:0 20px;">美团单张券价格为<span class="redColor">{{groupon_price}}</span>元 &nbsp;&nbsp;&nbsp;&nbsp;阳光档6小时团购价格<span class="redColor">等于</span>黄金档3小时美团价格</p>
                <el-button type="primary" @click="setSim">设置基准套餐</el-button>
            </div>
            
            
        </div>
         
        <!-- tab部分 -->
        <div class="tabContainer">
            <el-table :data="tableData" stripe style="width: 100%;text-align:center">
                <!-- <el-table-column :prop="item.bar" :label="item.name" fixed v-for="(item,index) in tabBar" :key="index">
                    <img :src="item.bar" alt="" v-if="item.name == '封面'">
                </el-table-column> -->

                <el-table-column prop="period_name" label="时段" fixed></el-table-column>
                <el-table-column prop="charmber_name" label="房型"></el-table-column>
                <el-table-column prop="normal_price" label="平日单价" width="200"></el-table-column>
                <el-table-column prop="weekend_price" label="周末单价"></el-table-column>
                <el-table-column prop="groupon_num" label="平日美团团购券数"></el-table-column>
                <el-table-column prop="weekend_groupon_num" label="周末美团团购券数"></el-table-column>
                <el-table-column prop="combo_name" label="提成基准套餐" width="200"> </el-table-column>
                <el-table-column  label="操作" prop="price_id" v-if="limitList.length>0">
                    <template  slot-scope="scope">            
                        <span v-for="(item,indexLimit) in limitList" :key="indexLimit" class="lightFont" @click="theClick(item.url,scope.row.price_id,scope.row.charmber_id,scope.row.period_id)">
                            <i>{{item.name}}</i><i v-if="indexLimit != limitList.length-1">&nbsp;|&nbsp;</i>
                        </span>
                    </template>

                </el-table-column>
                <el-table-column label="操作"  v-else>/</el-table-column>

            </el-table>
                        
        </div>
        <!-- 分页部分 -->
        <!-- 分页部分 -->
        <el-pagination
            background
            layout="total, prev, pager, next, jumper"
            @current-change="changePage"
            :page-size="size"
            :current-page.sync="pageNum"
            :hide-on-single-page=true
            :total="total">{{total}}
        </el-pagination>
        <!-- 设置基准套餐 -->
        <el-dialog title="设置基准套餐" :visible.sync="simBlur" class="business">
            <el-form :model="form">
                
                <el-form-item label="" label-width="400">
                <el-select v-model="simVal" placeholder="请选择..">
                    <el-option label="请选择.." value=""></el-option>
                    <el-option v-for="(item,index) in simArray" :key="index" :label="item.combo_name" :value="item.combo_id"></el-option>
                </el-select>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="simBlur = false">取 消</el-button>
                <el-button type="primary" @click="simComfrim">确 定</el-button>
            </div>
        </el-dialog>
       <!-- 编辑 -->
       <el-dialog title="编辑计时房价" :visible.sync="ticket" class="business">
            <el-form :model="ticketF">
                <el-form-item label="平日美团券数" label-width="107px"  class="itemTxt">
                    <el-input v-model="ticketF.day" autocomplete="off" class="longInput"></el-input>
                </el-form-item>
                <el-form-item label="周末美团券数" label-width="107px"  class="itemTxt">
                    <el-input v-model="ticketF.week" autocomplete="off" class="longInput"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="ticket = false">取 消</el-button>
                <el-button type="primary" @click="ticketComfrim">确 定</el-button>
            </div>
        </el-dialog>
    </div>
</template>
<style lang="scss" scoped>

#memuBox{
    .redColor{color:red}
    .el-select{
        width:370px;
        margin-left:50px;
    }
    .el-table{
        .el-table__row{
            td{
                height: 40px;
            }   
        }
        
    } 
    .el-form{padding-left:25px}
} 
</style>
<script>
import { abc } from "../../../../js/abc.js";
import {potUrl} from '../../../../js/config_url.js';
// import {draggable} from 'vuedraggable';
var url= potUrl.rpriceList;
export default {
    data(){
        return {          
            tableData:[],
            total:50,
            size:20,
            pageNum:1,
            form:{
                size:20,
                page:1
            },
            ticketF:{
                day:0,
                week:0
            },
            simBlur:false,
            ticket:false,
            simVal:'',
            pageNum:1,//page
            limitList:[],
            simArray:[],
            groupon_price:'',
            params:{
                groupon:'groupon'
            },
            day:'',
            week:''
        }
    },
    mounted(){
        var that = this;
        abc.get(that,potUrl.simplelist,{},function(res) {
            console.log('sim',res)
            that.simArray = res.data
        })
        abc.get(that,url,that.form,function(res){
            that.total = parseInt(res.data.total)
            that.tableData =  res.data.list;
            that.groupon_price = res.data.groupon_price;
            console.log(that.tableData)
        });//列表
        
    },
    created(){
        var that = this;
        setTimeout(() => {
            var str = $('.router-link-active').attr('href');
            abc.limit(that,str)// 权限  
        }, 500)       
    },
    methods:{
        theClick(url,a,b,c){
            var that = this;
            if(url == 'edit'){
                abc.get(that,potUrl.rprice_detail,{price_id:a},function(res){
                    that.ticketF.day = res.data.groupon_num;
                    that.ticketF.week = res.data.weekend_groupon_num;
                })
                console.log(that.ticketF)
                that.params.period_id = c;
                that.params.charmber_id = b;
                that.params.price_id = a;
                that.ticket = true    
            }else{
                that.$message({
                    type:'success',
                    message:"12112212",
                    duration:'1000'
                })
            }
            
            
        },           
        changePage(val){
            var that = this;
            that.pageNum = val;
            this.form.page = val;
           abc.getList(that,url,that.form);
        },
        setSim(){
            this.simBlur = true
        },
        simComfrim(){
            var that = this;
            abc.post(that,potUrl.setpercentage,{combo_id:that.simVal},function(res){
                if(res.code == 200){
                   that.simBlur = false;
                    abc.getList(that,url,that.form);//列表
                    that.$message({
                        type:'success',
                        message:"设置成功",
                        duration:'1000'
                    })
                }
            })
        },
        ticketComfrim(){
            var that = this;
            if (that.ticketF.day == '' || that.ticketF.week == '') {
                that.$message({
                    type:"success",
                    message:'美团券不能为空',
                    duration:'1000'
                })
                return
            } else {
                that.params.groupon_num = that.ticketF.day;
                that.params.weekend_groupon_num = that.ticketF.week;
                normal_price = that.params.groupon * that.groupon_price / 1.8;
                that.params.normal_price = abc.ModifyPrice(normal_price)
                weekend_price = that.params.weekend_groupon * that.groupon_price / 1.8;
                that.params.weekend_price = abc.ModifyPrice(weekend_price)
            } 
            abc.post(that,potUrl.rprice_edit,that.params,function(res){
                that.ticket = false;
                abc.get(that,url,that.form,function(res){
                    that.total = parseInt(res.data.total)
                    that.tableData =  res.data.list;
                    that.groupon_price = res.data.groupon_price
                });//列表
            })
        }
    }
}

</script>